package com.power.sifa.net.formact.service.impl;

import com.plf.common.exception.BusinessException;
import com.plf.common.utils.StringUtil;
import com.power.sifa.approve.model.Apl_main;
import com.power.sifa.correction.model.Crc_person;
import com.power.sifa.correction.service.Crc_personService;
import com.power.sifa.net.formact.QueryFormDataUtil;
import com.power.sifa.net.formact.service.FormNextService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

@Service
@Slf4j
@Transactional(rollbackFor = Exception.class)
public class FormNextCondeployImpl implements FormNextService {

    @Resource
    private Crc_personService Crc_personService;

    @Override
    public void before(String applyid, Map<String, Object> formData) {
        // 设置拟受理单位, 默认南昌市
        Map<String, Object> masterObj = QueryFormDataUtil.getMasterData(formData);
        masterObj.put("regsectionid", "3601001000");

        // name字段会在前端被控件赋值为id, 需要重新查询赋值回正确的值
        Map<String, Object> extendObj = QueryFormDataUtil.getExtendData("apl_condeploy_person", formData);
        String perid = (String) extendObj.get("perid");
        if(StringUtil.isEmpty(perid)) {
            throw new RuntimeException("布控编号不能为空");
        }
        Crc_person personObj = this.Crc_personService.getById(perid);
        if(null == personObj) {
            throw new RuntimeException("布控人员已失效");
        }
        masterObj.put("applyname", personObj.getName());
    }

    @Override
    public void after(String applyid, Map<String, Object> formData) {

    }

    @Override
    public void submit(String applyid, Apl_main mainObj) {

    }

    @Override
    public void save(String applyid, Map<String, Object> formData) {

    }
}
